﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;


namespace UI
{
    public class UICopySweepItem :MonoBehaviour
    {

        public UILabel sweepCount;
        public GameObject dropItem;
        public UIGrid dropItemGrid;
        public UIScrollView dropScrollView;

        public UILabel awardCoinTxt;
        public UILabel awardExpTxt;
        public UILabel awardEquipTxt;

        public UILabel awardCoinNumber;
        public UILabel awardExpNumber;

        string sweepCountTxt;

        public TweenAlpha alpha;

        #region ExpBar
        public UILabel playerLevelLabel;
        public UIProgressBar expBar;
        public UILabel expNumLabel;
        #endregion

        void Awake()
        {
            awardCoinTxt.text = TableTextBlo.GetText( "get_coin" );
            awardExpTxt.text = TableTextBlo.GetText( "get_exp" );
            awardEquipTxt.text = TableTextBlo.GetText( "get_award" );

            sweepCountTxt = TableTextBlo.GetText( "copy_sweep_times" );
        }

        public void Init(UIDropSimpleParser parser,int times)
        {
            this.sweepCount.text = string.Format( sweepCountTxt, times );
            this.awardCoinNumber.text = parser.Coin+"";
            this.awardExpNumber.text = parser.Exp +"";
            UIScrollView sv = transform.parent.parent.GetComponent<UIScrollView>();
            foreach (var it in parser.items)
            {
                if( it.Goods )
                {
                    if (it.number <= 0) continue;

                    GameObject obj = GameObject.Instantiate( dropItem ) as GameObject;
                    obj.SetActive( true );
                    obj.transform.SetParent( dropItemGrid.transform );
                    obj.transform.localScale = Vector3.one * 0.85f;

                    var drop = obj.GetComponent<CommonIcon>();
                    
                    drop.SetData(it.id, true, it.number);
                    UIDragScrollView dsv = obj.AddComponent<UIDragScrollView>();
                    dsv.scrollView = sv;
                }
            }

            
            playerLevelLabel.text = TableTextBlo.GetText("level") + StaticData.playerData.level;
            if (!StaticData.playerData.isLevelMax)
            {
                expNumLabel.text = StaticData.playerData.exp + "/" + StaticData.playerData.maxExp;
                expBar.value = (float)StaticData.playerData.exp / (float)StaticData.playerData.maxExp;
            }
            else
            {
                expNumLabel.text = "满值";
                expBar.value = 1f;
            }
        }
    }
}